

#ifndef _UCPUBLISHREACTORS_H
#define _UCPUBLISHREACTORS_H

#include <vector>
#include "zrxobject.h"
#include "zacarray.h"
#include "zacpldsddata.h"
#include "zacpldsdentry.h"
#include "zacdmmutils.h"
#include "zacdmmeplotproperty.h"
#include "zacplploterrorhandler.h"
#include "zacplplotlogger.h"

class UcPublishReactorManager;
class UcPublishReactor;
class UcPublishReactorInfo;

class UcPublishBeginJobInfo;
class UcPublishSheetInfo;

class UcNameValuePair
{
public:
    UcNameValuePair()
    {
        m_pName = NULL;
        m_pValue = NULL;
    };
    ~UcNameValuePair()
    {
        if (NULL != m_pName)
            delete [] m_pName;
        if (NULL != m_pValue)
            delete [] m_pValue;
    };
    UcNameValuePair(const ZTCHAR *name, const ZTCHAR *value)
    {
#ifdef UNICODE
        if (NULL != name) {
            m_pName = new ZTCHAR[::wcslen(name) + 1];
            ::wcscpy(m_pName, name);
        } else
            m_pName = NULL;

        if (NULL != value) {
            m_pValue = new ZTCHAR[::wcslen(value) + 1];
            ::wcscpy(m_pValue, value);
        } else
            m_pValue = NULL;
#else
		if (NULL != name) {
			m_pName = new ZTCHAR[::strlen(name) + 1];
			::strcpy(m_pName, name);
		} else
			m_pName = NULL;

		if (NULL != value) {
			m_pValue = new ZTCHAR[::strlen(value) + 1];
			::strcpy(m_pValue, value);
		} else
			m_pValue = NULL;
#endif
    }
    UcNameValuePair(const UcNameValuePair &src)
    : m_pName(NULL),
      m_pValue(NULL)
    {
        *this = src;
    }
    const ZTCHAR * name() const {return m_pName;};
    const ZTCHAR * value() const {return m_pValue;};
    void setName(const ZTCHAR * name)
    {
#ifdef UNICODE
        if (NULL != m_pName)
            delete [] m_pName;
        if (NULL != name) {
            m_pName = new ZTCHAR[::wcslen(name) + 1];
            ::wcscpy(m_pName, name);
        } else
            m_pName = NULL;
#else
		if (NULL != m_pName)
			delete [] m_pName;
		if (NULL != name) {
			m_pName = new ZTCHAR[::strlen(name) + 1];
			::strcpy(m_pName, name);
		} else
			m_pName = NULL;
#endif
    }
    void setValue(const ZTCHAR * value)
    {
#ifdef UNICODE
        if (NULL != m_pValue)
            delete [] m_pValue;
        if (NULL != value) {
            m_pValue = new ZTCHAR[::wcslen(value) + 1];
            ::wcscpy(m_pValue, value);
        } else
            m_pValue = NULL;
#else
		if (NULL != m_pValue)
			delete [] m_pValue;
		if (NULL != value) {
			m_pValue = new ZTCHAR[::strlen(value) + 1];
			::strcpy(m_pValue, value);
		} else
			m_pValue = NULL;
#endif
    }
    UcNameValuePair & operator= (const UcNameValuePair &src)
    {
        if (this == &src)
            return *this;

        setName(src.m_pName);
        setValue(src.m_pValue);
        return *this;
    }

private:
    ZTCHAR * m_pName;
    ZTCHAR * m_pValue;
};

typedef std::vector<UcNameValuePair> UcNameValuePairVec;

class UcPublishBeforeJobInfo
{
public:
    UcPublishBeforeJobInfo() {};
    virtual ~UcPublishBeforeJobInfo() {};
    virtual const UcPlDSDData * GetDSDData() = 0;
    virtual const UcNameValuePairVec
        GetPrivateData(const ZTCHAR * sectionName) = 0;
    virtual bool WritePrivateSection(const ZTCHAR * sectionName,
        const UcNameValuePairVec nameValuePairVec) = 0;
    virtual bool JobWillPublishInBackground() = 0;
};

class UcPublishBeginJobInfo
{
public:
    UcPublishBeginJobInfo() {};
    virtual ~UcPublishBeginJobInfo() {};
    virtual const UcPlDSDData * GetDSDData() = 0;
    virtual const UcNameValuePairVec
        GetPrivateData(const ZTCHAR * sectionName) = 0;
    virtual bool WritePrivateSection(const ZTCHAR * sectionName,
        const UcNameValuePairVec nameValuePairVec) = 0;
    virtual bool JobWillPublishInBackground() = 0;
    virtual UcPlPlotLogger * GetPlotLogger() = 0;
};

class UcPublishSheetInfo
{
public:
    UcPublishSheetInfo() {};
    virtual ~UcPublishSheetInfo() {};
    virtual const UcPlDSDEntry * GetDSDEntry() = 0;
    virtual const ZTCHAR * GetUniqueId() = 0;
    virtual UcPlPlotLogger * GetPlotLogger() = 0;
};

class UcPublishAggregationInfo
{
public:
    UcPublishAggregationInfo() {};
    virtual ~UcPublishAggregationInfo() {};
    virtual void AddGlobalProperties(UcDMMEPlotPropertyVec props) = 0;
    virtual void AddGlobalResources(UcDMMResourceVec resources) = 0;
    virtual UcPlPlotLogger * GetPlotLogger() = 0;
    virtual const ZTCHAR* dwfFileName() = 0;
    virtual const ZTCHAR* dwfPassword() = 0;
};

class UcPublishReactorInfo
{
public:
    UcPublishReactorInfo() {};
    virtual ~UcPublishReactorInfo() {};

    virtual const ZTCHAR* dwfFileName() = 0;
    virtual const ZTCHAR* tempDwfFileName() = 0;
    virtual const ZTCHAR* dwfPassword() = 0;

    virtual bool isMultiSheetDwf() = 0;
};

class UcPublishReactor : public UcRxObject
{
public:
    virtual void OnAboutToBeginBackgroundPublishing(UcPublishBeforeJobInfo
        *pInfo);
    virtual void OnAboutToBeginPublishing(UcPublishBeginJobInfo *pInfo);
    virtual void OnBeginPublishingSheet(UcPublishSheetInfo *pInfo);
    virtual void OnBeginAggregation(UcPublishAggregationInfo *pInfo);
    virtual void OnAboutToEndPublishing(UcPublishReactorInfo *pInfo);
    virtual void OnAboutToMoveFile(UcPublishReactorInfo *pInfo);
    virtual void OnEndPublish(UcPublishReactorInfo *pInfo);
    virtual void OnCancelledOrFailedPublishing(UcPublishReactorInfo *pInfo);

    virtual ~UcPublishReactor() {};

protected:

    UcPublishReactor() {};
};

inline void
    UcPublishReactor::OnAboutToBeginBackgroundPublishing(UcPublishBeforeJobInfo
    *pInfo) {};

inline void
    UcPublishReactor::OnAboutToBeginPublishing(UcPublishBeginJobInfo *pInfo) {};

inline void
    UcPublishReactor::OnBeginPublishingSheet(UcPublishSheetInfo *pInfo) {};

inline void
    UcPublishReactor::OnBeginAggregation(UcPublishAggregationInfo *pInfo) {};

inline void
    UcPublishReactor::OnAboutToEndPublishing(UcPublishReactorInfo *pInfo) {};

inline void
    UcPublishReactor::OnAboutToMoveFile(UcPublishReactorInfo *pInfo) {};

inline void
    UcPublishReactor::OnEndPublish(UcPublishReactorInfo *pInfo) {};

inline void
    UcPublishReactor::OnCancelledOrFailedPublishing(UcPublishReactorInfo
    *pInfo) {};

void UcGlobAddPublishReactor(UcPublishReactor *pReactor);

void UcGlobRemovePublishReactor(UcPublishReactor *pReactor);

typedef void (__cdecl * UCGLOBADDPUBLISHREACTOR)(UcPublishReactor * pReactor);
typedef void (__cdecl * UCGLOBREMOVEPUBLISHREACTOR)(UcPublishReactor * pReactor);

#endif

